package com.blb.thread;

import java.io.*;

public class Test2 {

    public static void main(String[] args) {
        new Thread(()->{
            File file1=new File("D:\\blb\\java 第一阶段\\221101-异常与IO-day01\\03作业");
            readFile(file1);
        }).start();
    }

    public static void readFile(File file){
        if (file.isDirectory()){
            File[] files = file.listFiles();
            if (files!=null){
                for(File file1:files){
                    readFile(file1);
                }
            }
        }else {
            System.out.println(file.getName());
            //读文件
            try {
                //得到字节流
                FileReader fileReader=new FileReader(file);
                //缓冲流
                BufferedReader bufferedReader=new BufferedReader(fileReader);
                String read=null;
                while ((read=bufferedReader.readLine())!=null){
                    System.out.println(read);
                }
                fileReader.close();
                bufferedReader.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
